#ifndef HC_INPUT_COMMAND_EASY_H
#define HC_INPUT_COMMAND_EASY_H

#include <hcInputCommand.hpp>

class hcInputCommandEasy
{
	vector<hcInputCommand> lisCmd;
	hcInputCommand last_cmd;

public:


	Addrhc get_int(string parName, int_hc defaultValue = 0)
	{
		return last_cmd.getPar_int(parName, defaultValue);
	}
	bool get_bool(string parName)
	{
		return last_cmd.getPar_bool(parName);
	}
	string get_str(string parName)
	{
		return last_cmd.getPar_str(parName);
	}


private:

	bool set_format_config(hcInputCommand& arg2, string strarg)
	{
		vector<string> lis2 = hcStr::split_noempty(strarg, "-");
		int k = 0;
		for (int j = 0; j < lis2.size(); j++)
		{
			string arg_name = hcStr::inGet(lis2[j], "", " ");
			string arg_type = hcStr::inGet(lis2[j], " ", "");
			if (arg_name == "")
			{
				arg_name = lis2[j];

				if (arg_name == "") {
					return false;
				}
				arg2.add_argument("-" + arg_name, "bool");
				k++;
			}
			else
			{
				if (arg_type == "%%s") {
					arg2.add_argument("-" + arg_name, "str");
					k++;
				}
				else if (arg_type == "%%d") {
					arg2.add_argument("-" + arg_name, "int");
					k++;
				}
				else {
					return false;
				}
			}
		}
		return true;
	}

	//多个用
	bool check(string cmdName = "default")
	{
		for (int i = 0; i < lisCmd.size(); i++)
		{
			hcInputCommand& cmd = lisCmd[i];
			if (cmd.checkName(cmdName))
			{
				last_cmd = cmd;
				return true;
			}
		}
		return false;
	}
public:
	//一键快速处理
//  dump -mod %%s -o %%s -hexs %%s -l -k \n
//	searchhex -mod %%s
// 
	//单命令解析,一般用在命令行处理
	void Config_one(string strConfig)
	{
		lisCmd.clear();
		hcInputCommand arg2("default");
		if (set_format_config(arg2, strConfig))
		{
			lisCmd.push_back(arg2);
		}
	}
	//多命令解析设置,一般用在命令解析, 
	//参数1: 命令配置
	//	  格式为:  
	//		   命令名 + 其他组合
	//			-标记   %%s       -->字符串
	//			-标记	%%d		  -->数字/0x数字
	//			-标记			  --类型
	//	 多条命令用分隔符分开
	//		"dump -a %%s -b -s %%s -n %%d | hook -addr %%d -api %%s -u"
	//		"ping -ip %%s -n %%d  \n   ipconfig   \n  "
	//	 所有的标记必须有符号'-',方便识别标记还是值
	//参数2: 分割符,分割多条配置用的
	//		"|"   "\n"   
	void Config_Multi(string strConfig, string lpSeparator)
	{
		lisCmd.clear();
		vector<string> lis = hcStr::split_noempty(strConfig, lpSeparator); //分割
		for (int i = 0; i < lis.size(); i++)
		{
			string name = hcStr::inGet(lis[i], "", " ");
			string arg = hcStr::inGet(lis[i], " ", "");
			if (name == "") {
				continue;
			}
			hcInputCommand arg2(name);
			if (set_format_config(arg2, arg)) {
				lisCmd.push_back(arg2);
			}
		}
		return;
	}

	//检查命令 + 输入参数配对
	bool input(string cmdName, vector<string> pars)
	{
		//2.输入命令检查(多命令解析时候,获取命令
		if (!check(cmdName)) {
			return false;
		}

		//3.解析参数(输入参数)
		last_cmd.InputArgs(pars);
		return true;
	}

	bool input(string all_cmd)
	{
		vector<string> lis = hcStringAnalysis::command2words(all_cmd);
		if (lis.size() == 0) {
			return false;
		}
		string cmd = lis[0];
		lis.erase(lis.begin());
		return input(cmd, lis);
	}
};

#endif

